# -*- coding: utf-8 -*-
# @Time    : 2023/8/19
# @Author  : Yangyali
#
import loguru
import pytest
from loguru import logger
from playwright.sync_api import Playwright, expect, sync_playwright
from functools import wraps
from common.HttpReq import HttpReq
from common.util import write_to_yaml,clear_yaml,get_config_value
import pytest_playwright
from common.login_utils import login

@pytest.fixture(scope="session")
def httprequest():
    with sync_playwright() as playwright:
        httprequest=HttpReq(playwright)
        yield httprequest

@pytest.fixture(scope="session", autouse=True)
def setup_logger(request):
    # 获取测试类文件名
    test_file_name = request.node.name
    log_file = f"logs/{test_file_name}.log"

    logger.add(log_file)

def write_case_log(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        logger.info("{}开始执行".format(func.__name__))
        response=func(*args,**kwargs)
        logger.info("执行结果为{}".format(response.text()))
        logger.info("{}执行结束",format(func.__name__))

    return wrapper

